"""
运算符综合练习
学习目标：
1. 综合运用各种运算符
2. 解决实际问题
3. 巩固运算符知识
"""

print("=" * 60)
print(" " * 15 + "运算符综合练习")
print("=" * 60)
print()

# ==================== 练习1：计算器程序 ====================
print("=" * 60)
print("练习1：简单计算器")
print("=" * 60)

print("实现一个简单的计算器，支持加减乘除四则运算")
print()

num1 = 15
num2 = 4
operator = "/"

print(f"第一个数：{num1}")
print(f"第二个数：{num2}")
print(f"运算符：{operator}")
print()

if operator == "+":
    result = num1 + num2
    print(f"结果：{num1} + {num2} = {result}")
elif operator == "-":
    result = num1 - num2
    print(f"结果：{num1} - {num2} = {result}")
elif operator == "*":
    result = num1 * num2
    print(f"结果：{num1} * {num2} = {result}")
elif operator == "/":
    if num2 != 0:
        result = num1 / num2
        print(f"结果：{num1} / {num2} = {result}")
    else:
        print("错误：除数不能为0")
else:
    print("错误：不支持的运算符")

print()

# ==================== 练习2：成绩管理系统 ====================
print("=" * 60)
print("练习2：学生成绩管理系统")
print("=" * 60)

student_name = "张三"
math = 85
english = 92
chinese = 78
physics = 88
chemistry = 90

print(f"学生姓名：{student_name}")
print(f"数学：{math}分")
print(f"英语：{english}分")
print(f"语文：{chinese}分")
print(f"物理：{physics}分")
print(f"化学：{chemistry}分")
print("-" * 60)

# 计算总分和平均分
total = math + english + chinese + physics + chemistry
average = total / 5
print(f"总分：{total}分")
print(f"平均分：{average:.2f}分")

# 判断是否所有科目及格
all_pass = math >= 60 and english >= 60 and chinese >= 60 and physics >= 60 and chemistry >= 60
print(f"所有科目及格：{all_pass}")

# 判断是否有优秀科目（>=90）
has_excellent = math >= 90 or english >= 90 or chinese >= 90 or physics >= 90 or chemistry >= 90
print(f"有优秀科目：{has_excellent}")

# 等级评定
if average >= 90:
    grade = "优秀"
elif average >= 80:
    grade = "良好"
elif average >= 70:
    grade = "中等"
elif average >= 60:
    grade = "及格"
else:
    grade = "不及格"

print(f"综合等级：{grade}")

# 找出最高分和最低分
max_score = math
if english > max_score:
    max_score = english
if chinese > max_score:
    max_score = chinese
if physics > max_score:
    max_score = physics
if chemistry > max_score:
    max_score = chemistry

min_score = math
if english < min_score:
    min_score = english
if chinese < min_score:
    min_score = chinese
if physics < min_score:
    min_score = physics
if chemistry < min_score:
    min_score = chemistry

print(f"最高分：{max_score}分")
print(f"最低分：{min_score}分")
print(f"分差：{max_score - min_score}分")

print()

# ==================== 练习3：购物车系统 ====================
print("=" * 60)
print("练习3：购物车结算系统")
print("=" * 60)

# 商品信息
item1_name = "Python编程书"
item1_price = 89.0
item1_quantity = 2

item2_name = "无线鼠标"
item2_price = 79.0
item2_quantity = 1

item3_name = "机械键盘"
item3_price = 299.0
item3_quantity = 1

print("购物车商品：")
print(f"1. {item1_name}  ¥{item1_price} × {item1_quantity}")
print(f"2. {item2_name}  ¥{item2_price} × {item2_quantity}")
print(f"3. {item3_name}  ¥{item3_price} × {item3_quantity}")
print("-" * 60)

# 计算小计
subtotal1 = item1_price * item1_quantity
subtotal2 = item2_price * item2_quantity
subtotal3 = item3_price * item3_quantity

print(f"小计：")
print(f"  {item1_name}：¥{subtotal1}")
print(f"  {item2_name}：¥{subtotal2}")
print(f"  {item3_name}：¥{subtotal3}")

# 计算总价
total = subtotal1 + subtotal2 + subtotal3
print(f"\n商品总价：¥{total}")

# 会员折扣
is_vip = True
if is_vip:
    discount = 0.9  # 9折
    print(f"会员折扣：9折")
    total *= discount
    print(f"折后价格：¥{total:.2f}")

# 运费计算
free_shipping_threshold = 199
if total >= free_shipping_threshold:
    shipping_fee = 0
    print(f"满{free_shipping_threshold}免运费")
else:
    shipping_fee = 10
    print(f"运费：¥{shipping_fee}")

# 最终金额
final_total = total + shipping_fee
print(f"\n应付金额：¥{final_total:.2f}")

# 优惠券
has_coupon = True
coupon_amount = 20
if has_coupon:
    final_total -= coupon_amount
    print(f"使用优惠券：-¥{coupon_amount}")
    print(f"最终金额：¥{final_total:.2f}")

# 计算节省金额
saved = (subtotal1 + subtotal2 + subtotal3) - final_total
print(f"\n已节省：¥{saved:.2f}")

print()

# ==================== 练习4：员工工资计算 ====================
print("=" * 60)
print("练习4：员工工资计算系统")
print("=" * 60)

employee_name = "李四"
base_salary = 8000  # 基本工资
overtime_hours = 20  # 加班小时数
overtime_rate = 50  # 加班时薪

print(f"员工姓名：{employee_name}")
print(f"基本工资：¥{base_salary}")
print(f"加班时长：{overtime_hours}小时")
print(f"加班时薪：¥{overtime_rate}/小时")
print("-" * 60)

# 加班费
overtime_pay = overtime_hours * overtime_rate
print(f"加班费：¥{overtime_pay}")

# 绩效奖金
performance_score = 95
if performance_score >= 90:
    bonus = 2000
    bonus_level = "优秀"
elif performance_score >= 80:
    bonus = 1000
    bonus_level = "良好"
elif performance_score >= 70:
    bonus = 500
    bonus_level = "合格"
else:
    bonus = 0
    bonus_level = "待提升"

print(f"绩效分数：{performance_score} ({bonus_level})")
print(f"绩效奖金：¥{bonus}")

# 全勤奖
attendance_days = 22
work_days = 22
is_full_attendance = attendance_days == work_days
full_attendance_bonus = 500 if is_full_attendance else 0

print(f"出勤天数：{attendance_days}/{work_days}")
print(f"全勤奖：¥{full_attendance_bonus}")

# 应发工资
gross_salary = base_salary + overtime_pay + bonus + full_attendance_bonus
print(f"\n应发工资：¥{gross_salary}")

# 扣款
social_insurance = gross_salary * 0.105  # 社保 10.5%
housing_fund = gross_salary * 0.12  # 公积金 12%
tax_threshold = 5000  # 起征点

# 个人所得税（简化计算）
taxable_income = gross_salary - social_insurance - housing_fund - tax_threshold
if taxable_income <= 0:
    tax = 0
elif taxable_income <= 3000:
    tax = taxable_income * 0.03
elif taxable_income <= 12000:
    tax = taxable_income * 0.1 - 210
else:
    tax = taxable_income * 0.2 - 1410

print(f"\n扣款项目：")
print(f"  社保：¥{social_insurance:.2f}")
print(f"  公积金：¥{housing_fund:.2f}")
print(f"  个税：¥{tax:.2f}")

total_deduction = social_insurance + housing_fund + tax
print(f"  合计：¥{total_deduction:.2f}")

# 实发工资
net_salary = gross_salary - total_deduction
print(f"\n实发工资：¥{net_salary:.2f}")

print()

# ==================== 练习5：时间计算器 ====================
print("=" * 60)
print("练习5：时间计算器")
print("=" * 60)

total_seconds = 3665

print(f"总秒数：{total_seconds}秒")
print()

# 转换为时分秒
hours = total_seconds // 3600
remaining = total_seconds % 3600
minutes = remaining // 60
seconds = remaining % 60

print(f"转换结果：{hours}小时 {minutes}分 {seconds}秒")

print()

# 时间相加
time1_h, time1_m, time1_s = 2, 30, 45
time2_h, time2_m, time2_s = 1, 45, 30

print(f"时间1：{time1_h}小时 {time1_m}分 {time1_s}秒")
print(f"时间2：{time2_h}小时 {time2_m}分 {time2_s}秒")

# 全部转为秒
total_sec1 = time1_h * 3600 + time1_m * 60 + time1_s
total_sec2 = time2_h * 3600 + time2_m * 60 + time2_s
sum_seconds = total_sec1 + total_sec2

# 转回时分秒
sum_h = sum_seconds // 3600
sum_m = (sum_seconds % 3600) // 60
sum_s = sum_seconds % 60

print(f"时间相加：{sum_h}小时 {sum_m}分 {sum_s}秒")

print()

# ==================== 练习6：BMI健康指数 ====================
print("=" * 60)
print("练习6：BMI健康指数计算")
print("=" * 60)

name = "王五"
height = 1.75  # 米
weight = 70  # 千克
age = 28

print(f"姓名：{name}")
print(f"身高：{height}m")
print(f"体重：{weight}kg")
print(f"年龄：{age}岁")
print("-" * 60)

# 计算BMI
bmi = weight / (height ** 2)
print(f"BMI指数：{bmi:.2f}")

# BMI分类
if bmi < 18.5:
    category = "偏瘦"
    advice = "建议增加营养摄入"
elif bmi < 24:
    category = "正常"
    advice = "保持良好习惯"
elif bmi < 28:
    category = "偏胖"
    advice = "建议控制饮食，增加运动"
else:
    category = "肥胖"
    advice = "建议就医咨询，制定减重计划"

print(f"体重分类：{category}")
print(f"健康建议：{advice}")

# 标准体重计算（简化公式）
standard_weight = (height * 100 - 80) * 0.7
weight_diff = weight - standard_weight

print(f"\n标准体重：{standard_weight:.1f}kg")
if weight_diff > 0:
    print(f"超重：{weight_diff:.1f}kg")
elif weight_diff < 0:
    print(f"偏轻：{abs(weight_diff):.1f}kg")
else:
    print("体重标准")

print()

# ==================== 练习7：停车费计算 ====================
print("=" * 60)
print("练习7：停车场计费系统")
print("=" * 60)

# 停车时间（分钟）
park_minutes = 185
is_member = False

print(f"停车时长：{park_minutes}分钟")
print(f"会员身份：{is_member}")
print("-" * 60)

# 转换为小时（向上取整）
park_hours = (park_minutes + 59) // 60  # +59 实现向上取整
print(f"计费时长：{park_hours}小时")

# 计费规则：
# 1小时内：5元
# 1-3小时：每小时10元
# 3小时以上：每小时15元
# 会员打8折

if park_hours <= 1:
    fee = 5
elif park_hours <= 3:
    fee = 5 + (park_hours - 1) * 10
else:
    fee = 5 + 2 * 10 + (park_hours - 3) * 15

print(f"基础费用：¥{fee}")

# 会员折扣
if is_member:
    fee *= 0.8
    print(f"会员折扣：8折")
    print(f"优惠后：¥{fee:.2f}")

print(f"\n应付金额：¥{fee:.2f}")

print()

# ==================== 练习8：数字游戏 ====================
print("=" * 60)
print("练习8：数字特性判断")
print("=" * 60)

number = 153

print(f"数字：{number}")
print("-" * 60)

# 判断奇偶
if number % 2 == 0:
    print(f"奇偶性：偶数")
else:
    print(f"奇偶性：奇数")

# 判断正负
if number > 0:
    print(f"符号：正数")
elif number < 0:
    print(f"符号：负数")
else:
    print(f"符号：零")

# 判断是否是3的倍数
if number % 3 == 0:
    print(f"是3的倍数：是")
else:
    print(f"是3的倍数：否")

# 判断是否是水仙花数（三位数）
if 100 <= number <= 999:
    digit1 = number // 100  # 百位
    digit2 = (number % 100) // 10  # 十位
    digit3 = number % 10  # 个位
    
    if digit1 ** 3 + digit2 ** 3 + digit3 ** 3 == number:
        print(f"水仙花数：是 ({digit1}³ + {digit2}³ + {digit3}³ = {number})")
    else:
        print(f"水仙花数：否")

# 判断是否是完全平方数
sqrt = int(number ** 0.5)
if sqrt * sqrt == number:
    print(f"完全平方数：是 ({sqrt}² = {number})")
else:
    print(f"完全平方数：否")

print()

# ==================== 练习9：投票系统 ====================
print("=" * 60)
print("练习9：投票资格审核系统")
print("=" * 60)

voter_name = "赵六"
age = 17
is_citizen = True
has_id = True
is_registered = False

print(f"姓名：{voter_name}")
print(f"年龄：{age}岁")
print(f"公民身份：{is_citizen}")
print(f"有身份证：{has_id}")
print(f"已登记：{is_registered}")
print("-" * 60)

# 资格审核
print("资格审核：")

# 年龄要求
age_qualified = age >= 18
print(f"1. 年龄要求（>=18岁）：{age_qualified}")

# 公民身份
print(f"2. 公民身份：{is_citizen}")

# 证件要求
print(f"3. 身份证件：{has_id}")

# 登记状态
print(f"4. 选民登记：{is_registered}")

# 综合判断
can_vote = age_qualified and is_citizen and has_id and is_registered

print(f"\n最终结果：{can_vote}")

if can_vote:
    print("✅ 具有投票资格")
else:
    print("❌ 不具有投票资格")
    print("不符合条件：")
    if not age_qualified:
        print("  - 未满18岁")
    if not is_citizen:
        print("  - 非本国公民")
    if not has_id:
        print("  - 无身份证件")
    if not is_registered:
        print("  - 未进行选民登记")

print()

# ==================== 练习10：电费计算 ====================
print("=" * 60)
print("练习10：阶梯电价计算")
print("=" * 60)

household = "张三家"
electricity_usage = 350  # 用电量（度）

print(f"户名：{household}")
print(f"用电量：{electricity_usage}度")
print("-" * 60)

# 阶梯电价：
# 0-200度：0.5元/度
# 201-400度：0.6元/度
# 400度以上：0.8元/度

if electricity_usage <= 200:
    bill = electricity_usage * 0.5
    tier = "第一档"
elif electricity_usage <= 400:
    bill = 200 * 0.5 + (electricity_usage - 200) * 0.6
    tier = "第二档"
else:
    bill = 200 * 0.5 + 200 * 0.6 + (electricity_usage - 400) * 0.8
    tier = "第三档"

print(f"电价档位：{tier}")
print(f"电费：¥{bill:.2f}")

# 节能建议
if electricity_usage > 400:
    print("\n💡 用电量较高，建议：")
    print("  - 及时关闭不用的电器")
    print("  - 使用节能型电器")
    print("  - 合理设置空调温度")
elif electricity_usage > 200:
    print("\n💡 用电量适中，建议继续保持节能习惯")
else:
    print("\n✅ 用电量较低，节能意识很好！")

print()

# ==================== 总结 ====================
print("=" * 60)
print(" " * 20 + "练习完成！")
print("=" * 60)
print("""
通过以上练习，你已经掌握了：

✅ 算术运算符：进行各种数学计算
✅ 比较运算符：进行条件判断
✅ 逻辑运算符：组合复杂条件
✅ 赋值运算符：更新变量值
✅ 运算符优先级：正确的运算顺序

这些知识可以应用到：
- 计算器程序
- 成绩管理系统
- 购物车结算
- 工资计算
- 时间转换
- 健康指数
- 停车计费
- 数字分析
- 投票系统
- 阶梯计价

继续练习，熟能生巧！🎉
""")
print("=" * 60)

